﻿<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:iTuner"
  x:Class="iTuner.EditBlock"
  x:ClassModifier="internal"
  x:Name="EditBlockControl">

  <UserControl.Resources>

    <DataTemplate x:Key="EditModeTemplate">
      <TextBox
        Text="{Binding ElementName=EditBlockControl, Path=Text, UpdateSourceTrigger=PropertyChanged}"
        Margin="3,0,0,0" BorderThickness="0" Background="Transparent"
        Loaded="DoTextBoxLoaded"
        LostFocus="DoTextBoxLostFocus"
        KeyDown="DoTextBoxKeyDown" />
    </DataTemplate>

    <DataTemplate x:Key="ReadModeTemplate">
      <TextBlock
        Text="{Binding ElementName=EditBlockControl, Path=Text}"
        TextTrimming="CharacterEllipsis"
        Margin="3,1,0,1" />
        </DataTemplate>

    <Style TargetType="{x:Type local:EditBlock}">
      <Style.Triggers>
        <Trigger Property="IsInEditMode" Value="True">
          <Setter Property="ContentTemplate" Value="{StaticResource EditModeTemplate}" />
        </Trigger>
        <Trigger Property="IsInEditMode" Value="False">
          <Setter Property="ContentTemplate" Value="{StaticResource ReadModeTemplate}" />
        </Trigger>
      </Style.Triggers>
    </Style>
  </UserControl.Resources>
</UserControl>
